<?php
$bookingItem = new BWInputValue($bookingId);
$bookingList = new BTreeList($bookingItem);
$user = Blyn::app()->getCurrentUser();
?>
<?php
$form = $this->beginWidget('CActiveForm', array(
    "id" => "post-form-2",
    'enableAjaxValidation' => FALSE,
    'htmlOptions' => array('enctype' => 'multipart/form-data'),
        ));
?>
<?php
$url = $control->getAjaxLinkUrl('addToBookingCart', NULL, array(
    'bookingId' => $bookingId,'userId'=>$user->userId));
$updateId = $control->getAjaxContainerId();
?>
<script type="text/javascript">
// this script for collecting the form data and pass to the controller action and doing the on success validations
    function addToBookingCart() {

        var formData = new FormData($("#message-form")[0]);
        //var formElement = document.getElementById("message-form");
        //var formData = new FormData(formElement);

        $.ajax({
            url: '<?php echo $url; ?>',
            type: 'POST',
            data: formData,
            datatype: 'json',
            // async: false,
            beforeSend: function() {
                $("#ajax-loaderdiv").show();
            },
            success: function(html) {
                // on success do some validation or refresh the content div to display the uploaded images 
                jQuery("#<?php echo $updateId; ?>").html(html);
                //alert(data);
            },
            complete: function() {
                $("#ajax-loaderdiv").hide();
            },
            error: function() {
                alert("There may a error on uploading. Try again later");
            },
            cache: false,
            contentType: false,
            processData: false
        });

        return false;
    }
</script>
<div class="modal-header">
    <button type="button" class="close" data-dismiss="modal" aria-hidden="true">×</button>
    <h3>
        <?php
        echo $control->getAjaxLink(array('name' => '搜索列表', 'id' => 'showBookingList'), array(
            'findText' => $findText));
        ?>\
        预订场地
    </h3>
</div>

<div class="modal-body" >
    <table class="table table-bordered table-striped">
        <colgroup>
            <col class="span1">
            <col class="span7">
        </colgroup>
        <thead>
            <tr>
                <th>预订项属性</th>
                <th>预订项内容</th>
            </tr>
        </thead>
        <tbody>
            <?php if ($bookingList instanceof BTreeList) { ?>
                <tr>
                    <td>
                        <code>场地商名称</code>
                    </td>
                    <td>
                        <?php echo $bookingList->getItem('venderName')->value; ?>
                    </td>
                </tr>
                <tr><td> <code>场地名称</code> </td>
                    <td>
                        <?php echo $bookingList->getItem('courtDisplayName')->value; ?>
                    </td>
                </tr> 
                <tr><td> <code>所属地区</code> </td>
                    <td>
                        <?php
                        $addressId = $bookingList->getItem('region')->value;
                        $address = new BWAddress($addressId);
                        echo $address->fullName;
                        ?>
                    </td>
                </tr> 
                <tr><td> <code>详细地址</code> </td>
                    <td>
                        <?php echo $bookingList->getItem('courtAddress')->value; ?>
                    </td>
                </tr> 
                <tr><td> <code>场地价格</code> </td>
                    <td>
                        <?php echo $bookingList->getItem('price')->value; ?>
                    </td>
                </tr> 
                <tr><td> <code>场地图片</code> </td>
                    <td>
                    </td>
                </tr>
                <tr>
                    <td> <code>场地简介</code>  </td>                    
                    <td>
                        <?php echo $bookingList->getItem('courtDescription')->value; ?>
                    </td>

                </tr>
                <tr><td> <code>场地开始时间:(0-23)</code> </td>
                    <td>
                        <?php
                        $startTime = $bookingList->getItem('startTime')->value;
                        echo date('Y-m-d G:i:s', $startTime);
                        ?>
                    </td>
                </tr> 
                <tr><td> <code>场地结束时间:(0-23)</code> </td>
                    <td>
                        <?php
                        $endTime = $bookingList->getItem('endTime')->value;
                        echo date('Y-m-d G:i:s', $endTime);
                        ?>
                    </td>
                </tr> 
                <tr><td> <code>预订开始时间:(0-23)</code> </td>
                    <td>
                        <?php
                        $bookingStartTime = $bookingList->getItem('bookingStartTime')->value;
                        echo date('Y-m-d G:i:s', $bookingStartTime);
                        ?> 
                    </td>
                </tr> 
                <tr><td> <code>预订结束时间:(0-23)</code> </td>
                    <td>
                        <?php
                        $bookingEndTime = $bookingList->getItem('bookingEndTime')->value;
                        echo date('Y-m-d G:i:s', $bookingEndTime);
                        ?>
                    </td>
                </tr>
                <tr><td> <code>预订状态:</code> </td>
                    <td>
                        <?php
                        $bookingStatus = $bookingList->getItem('bookingStatus')->value;
                        echo  Yii::t('BWeSport', $bookingStatus);
                        ?>
                    </td>
                </tr>
                <tr><td> <code>预订人会员卡号:</code> </td>
                    <td>
                        <?php
                        echo $user->userId;
                        ?>
                    </td>
                </tr>
            <?php } ?>

        </tbody>
    </table>   
</div>

<div class="modal-footer">
    <button class="btn" data-dismiss="modal" aria-hidden="true">关闭</button>
    <button class="btn" data-dismiss="modal" aria-hidden="true" onclick="javascript:addToBookingCart()">加入预订清单</button>
</div>

<?php $this->endWidget(); ?>
